package com.mch.main.common;

import java.awt.BorderLayout;
import java.awt.Font;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;

import com.mch.main.tools.JVMResource;

public class MDebugPanel extends JPanel {
	private static final long serialVersionUID = 6312150209487611733L;
	private JTabbedPane tabbedPane;
	private JPanel panel;
	private JPanel panelEnv;
	private JPanel panel_2;
	private JScrollPane scrollPane;
	private RSyntaxTextArea textArea;
	private RSyntaxTextArea textAreaJVM;

	public MDebugPanel() {

		initGUI();
	}

	private void initGUI() {
		setLayout(new BorderLayout(0, 0));
		add(getTabbedPane(), BorderLayout.CENTER);
	}

	public JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			tabbedPane.addTab("New tab", null, getPanel(), null);
			tabbedPane.addTab("环境", null, getPanelEnv(), null);
			tabbedPane.addTab("New tab", null, getPanel_2(), null);
		}
		return tabbedPane;
	}

	public JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getScrollPane(), BorderLayout.CENTER);
		}
		return panel;
	}

	public JPanel getPanelEnv() {
		if (panelEnv == null) {
			panelEnv = new JPanel();
			panelEnv.setLayout(new BorderLayout(0, 0));
			panelEnv.add(getTextAreaJVM(), BorderLayout.CENTER);
		}
		return panelEnv;
	}

	public JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
		}
		return panel_2;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTextArea());
		}
		return scrollPane;
	}

	public RSyntaxTextArea getTextArea() {
		if (textArea == null) {
			textArea = new RSyntaxTextArea();
		}
		return textArea;
	}

	public RSyntaxTextArea getTextAreaJVM() {
		if (textAreaJVM == null) {
			textAreaJVM = new RSyntaxTextArea();
			textAreaJVM.setFont(new Font("宋体", Font.PLAIN, 14));
			textAreaJVM.setText(new JVMResource().printSummary());
		}
		return textAreaJVM;
	}
}
